package com.jprocms.module.cms.framework.mybatisplus;

import com.jpro.framework.common.util.json.JsonUtils;
import com.baomidou.mybatisplus.extension.handlers.AbstractJsonTypeHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.MappedJdbcTypes;
import org.apache.ibatis.type.MappedTypes;


/**
 * @author jprocms
 */
@Slf4j
@MappedTypes({Object.class})
@MappedJdbcTypes(JdbcType.VARCHAR)
public class ObjectJacksonTypeHandler extends AbstractJsonTypeHandler<Object> {
    public ObjectJacksonTypeHandler(Class<?> type) {
        super(type);
    }

    @Override
    public Object parse(String json) {
        return JsonUtils.parseObject(json, type);
    }

    @Override
    public String toJson(Object obj) {
        return JsonUtils.toJsonString(obj);
    }

}
